<?php

require_once("../../controllers/init.php");
require_once($FILE_SYSTEM_ROOT."/controllers/authentication.php");

function printEvents($music)
{

	foreach ($music as $musicevent)
	{
	//	$DTeventdate = new DateTime($musicevent->getDateTime());
		$Seventdate = $musicevent->getDateTime()->format('l jS F Y  H:i');
		echo "<b>".$Seventdate."</b> ";
		$choirs = $musicevent->getChoir();
		$choirsText="";
		if (strlen($choirs)>0)
		{
			$choirsText .='(';
			if (!(strpos($choirs,'B') === false)) $choirsText .= "Boys  ";
			if (!(strpos($choirs,'G') === false)) $choirsText .= "Girls  ";
			if (!(strpos($choirs,'C') === false)) $choirsText .= "Boys (optional Girls), ";
			if (!(strpos($choirs,'L') === false)) $choirsText .= "Lay Clerks  ";
			$choirsText = substr($choirsText,0,-2);
			if (strlen($choirs)>0) $choirsText .=')';
		}
		else $choirsText = "(No Choir)";
		echo $choirsText;
		
		
		echo "<br>\n";
		if ($musicevent->getPsalms() != "")     echo "Psalm ".$musicevent->getPsalms()."<br>\n"; 
		if ($musicevent->getHymns() != "")      echo "Hymns ".$musicevent->getHymns()."<br>\n"; 
		if ($musicevent->getIntroit() != "")    echo $musicevent->getIntroit()."<br>\n"; 
		if ($musicevent->getResponses() != "")  echo $musicevent->getResponses()." Responses<br>\n"; 
		if ($musicevent->getMass() != "")       echo $musicevent->getMass()."<br>\n"; 
		if ($musicevent->getCanticles() != "")  echo $musicevent->getCanticles()."<br>\n"; 
		if ($musicevent->getAnthem() != "")     echo $musicevent->getAnthem()."<br>\n"; 
	
	
		echo "<br>\n";
	}
	
}

?>


<html>
<head>
</head>
<body>

<?php
$date = new DateTime('now');
$dateStr = $date->format("l jS F Y");
echo "<h1>Forthcoming Music</h1>";
echo "<h2>from ".$dateStr."</h2>";

$choirtext = "";
$choircode = "";

switch($_GET['choir'])
{
	case 'girls':
		$choirtext = "Girls";
		$choircode = "girls";
		break;
		
	case 'boys':
		$choirtext = "Boys";
		$choircode = "boys";
		break;
		
	case 'clerks':
		$choirtext = "Lay Clerks";
		$choircode = "clerks";
		break;
		
	case 'all':
		$choirtext = "All";
		$choircode = "all";
		break;
}

echo "<h2>$choirtext</h2>\n";
$resultset = new MusicResultSet($choircode);
$date = new DateTime('yesterday');
$resultset->setStartDate($date);
$music = $resultset->getMusic();
printEvents($music);

?>
</body>
</html>